<!doctype html>
<html>
  <head>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-132775238-1"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-132775238-1');
    </script>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
    <script type="module" src="../rapidoc-min.js"></script>
  </head>
  <body>
    <rapi-doc id="thedoc"
      spec-url = "../specs/events.yaml" 
      allow-authentication = "false"
      allow-server-selection = "false"
      show-header="false"
      render-style = "focus"
    > 
    </rapi-doc>

    <script>
      document.addEventListener('DOMContentLoaded', (event) => {
        let docEl = document.getElementById("thedoc");

        docEl.addEventListener('before-render', (e) => {
          e.detail.spec.info.title = "EVENTS - This text is updated during `before-render` event";
        });

        docEl.addEventListener('after-try', (e) => {
          console.log("Hello from 'after-try' event ");
        });

        docEl.addEventListener('before-try', (e) => {
          if (e.detail.request.method === 'GET') {
            const url = new URL( e.detail.request.url);
            url.searchParams.append('delay', '3');
            e.detail.request.url = url.searchParams.toString();
          }
        });

        docEl.addEventListener('before-try', (e) => {
          if (e.detail.request.method === 'POST') {
            setTimeout(() => {
              e.detail.controller.abort();
            }, 0);
          }
        });

        docEl.addEventListener('request-aborted', (e) => {
          console.log("POST Requests are aborted in 'before-try' event ");
        });
      })
    </script>

  </body>
</html>